<div class="_top">
	<div class="_top_nav">
		<div class="left">
			<a href="#default/main">首页</a>
			{{#if loginer}}
            {{#if bus_info.info.qq}}
            <a title="QQ聊天" target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin={{bus_info.info.qq}}&site=qq&menu=yes">
                <img src="/images/qq-chat.png" class="qq" />
            </a>
            {{/if}}
			<a event-click="{{'$Event.user_collect_bus'}}" title="{{$Cache.is_collect_current_bus&&'点击取消收藏'||'点击收藏'}}">
				{{$Cache.is_collect_current_bus&&'已收藏'||'点击收藏'}}
			</a>
			<a href="personal-beta.html">
				{{loginer.info.name}}
			</a>
			<a event-click="{{'$Event.user_login_out'}}">
				注销
			</a>
			{{#else}}
			<a href="#default/sign?id=1{{$Cache.cb_url}}">登陆</a>
			<a href="#default/sign?id=2{{$Cache.cb_url}}">注册</a>
			{{/if}}
		</div>
		<div class="right">
			<a target="_blank" href="#default/cart" class="icon-cart3">
				购物车
			</a>
		</div>
	</div>
</div>
<div class="navbox">
	<div class="box">
		<div class="logo">
            <a href="#default/main">
			{{#if bus_info.info.logo_url}}
			<img bind-src="{{bus_info.info.logo_url}}?imageView/1/w/200/h/200" />
			{{/if}}
			<span>{{bus_info.info.title}}</span>
		    </a>
        </div>
        
		<div class="navs">
			<a href="#default/goodslist">全部新品</a>
			<a href="#default/tags">精品分类</a>
			<a href="#default/storeinfo">关于我们</a>
			<a href="#default/help">省钱攻略</a>
		</div>
	</div>
</div>
<!--背景图片-->
{{#if bus_info.config.is_use_bg_img}}
    {{#if bus_info.config.is_bg_img_alpha}}
    <div class="themeimgblock"></div>
    {{/if}}
    <img style="position: fixed;width: 100%;height: 100%;z-index: -2;top:0;left:0;" bind-src="{{bus_info.config.using_bg_img}}{{#if bus_info.config.is_bg_img_blur}}?imageMogr2/blur/10x10{{/if}}">
{{/if}}
<link rel="stylesheet" type="text/css" href="/css/catering/pc_top.css" />
<script type="text/vm">
	 function(vm) {
        require(["common", "coAjax", "href", "eventManager","queryString"], function(jSouper, coAjax, href, eventManager,queryString) {
            if (location.pathname !== "/sign_in.html") {
                var cb_url = "&cb_url=" + encodeURIComponent(location.href);
                App.set("$Cache.cb_url", cb_url);
                window.addEventListener("hashchange",function(){
                    App.set("$Cache.cb_url", cb_url);
                });
            } else {
                App.set("$Cache._in_sign_in_or_up", true);
            }
            //注销功能 
            App.set("$Event.user_login_out", function() {
                coAjax.get(appConfig.user.login_out_url, function() {
                    App.set("loginer", null);
                    if (href.isUser()) {
                        href.toLogin();
                    }
                });
            });
            //获取登陆用户的信息 
            /* 
             * 管理员相关的页面无需登录
             */
            var no_user_login_pages = {
                "/admin-beta.html": 1,
                "/admin-login.html": 1
            }
            if (no_user_login_pages[location.pathname]) {
                App.set("$Cache.is_in_admin", true);
                return;
            }
            console.log("获取登陆者信息……", location.pathname); /* * 获取登录者信息 */
            function _check_collect_bus(collectBus) {
                var is_collect = true;
                if (jSouper.indexOf(collectBus, appConfig.bus_id) === -1) {
                    is_collect = false;
                }
                App.set("$Cache.is_collect_current_bus", is_collect)
            };
            function user_login_success(data) {
                console.log("登录者信息：", data.result);
                userInfo = data.result;
                App.set("loginer", userInfo);
                //触发相关事件 
                eventManager.fire("getLoginer");
                //校验是否已经收藏过此商家 
                var collectBus = userInfo.collectBus || [];
                _check_collect_bus(collectBus);
            };
            function user_login_error(errorCode) {
                var muse_login_pages = {
                        "/personal-beta.html": 1,
                        "/cart-beta.html": 1
                    }
                    //未登录，不可进入个人页，强制跳转到登录页 
                if (muse_login_pages[location.pathname]) {
                    href.toLogin();
                }
                //触发相关事件 
                eventManager.reject("getLoginer");
            };
            coAjax.get(appConfig.user.loginer,user_login_success ,user_login_error);
            //收藏功能 
            App.set("$Event.user_collect_bus", function() {
                if (App.get("$Cache.is_collect_current_bus")) {
                    coAjax["delete"](appConfig.user.collectBus_remove, {
                        bus_id: appConfig.bus_id
                    }, function(result) {
                        alert("已经取消收藏");
                        App.set('$Cache.is_collect_current_bus', false);
                        _check_collect_bus(result.result);
                    }, function(errorCode, xhr, errorMsg) {
                        alert("error", errorMsg)
                    });
                } else {
                    coAjax.post(appConfig.user.collectBus_add, {
                        bus_id: appConfig.bus_id
                    }, function(result) {
                        alert("success", "收藏成功");
                        App.set('$Cache.is_collect_current_bus', true);
                        _check_collect_bus(result.result);
                    }, function(errorCode, xhr, errorMsg) {
                        alert("error", errorMsg)
                    });
                }
            });
            App.set("$Event.top.show_bus_qrcode", function() {
                App.model.toggle("$Cache.top.is_show_bus_qrcode");
            });
            var QueryString=new queryString(location.hash);
            var recommender_id=QueryString.get("rcid");
            if (recommender_id) {
                //将推荐者的信息保存起来，或者直接覆盖上一个推荐者，以最后一个推荐者为准
                LS.set("recommender_id",recommender_id);
            }
            App.set("$Cache.recommender_id", recommender_id);
		});
	}
</script>